package com.set.mobileapp.custom;

import com.set.mobileapp.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class EditTextWithLabel extends LinearLayout {
	TextView label;
	EditText text;
	ImageView delText;

	public EditTextWithLabel(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.edit_text_with_lable, this, true);
		label = (TextView) v.findViewById(R.id.editTextWizLableLable);
		text = (EditText) v.findViewById(R.id.editTextWizLableText);
		delText = (ImageView) v.findViewById(R.id.editTextWizLableClean);
		delText.setOnClickListener(new CleanEditText());
	}

	class CleanEditText implements OnClickListener {

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			if (text.isEnabled()) {
				text.setText(null);
			}
		}

	}

	public void setError(String error) {
		text.setError(error);
	}

	public boolean setFocus() {
		return text.requestFocus();
	}

	public EditText getEditText() {
		return text;
	}

	public TextView getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label.setText(label);
	}

	public void setEditTextHint(String hint) {
		this.text.setHint(hint);
	}

	public void setEditTextReadOnly(Boolean flg) {
		this.text.setEnabled(!flg);
	}

	public void setEditTextContent(String txt) {
		this.text.setText(txt);
	}

	public void setEditTextLines(int line) {
		this.text.setLines(line);
	}

	public void setCleanBtnVisible(Boolean flg) {
		if (flg) {
			this.delText.setVisibility(VISIBLE);
		} else {
			this.delText.setVisibility(INVISIBLE);
		}
	}

	public void setEditTextInputType(int type) {
		this.text.setInputType(type);
	}
}
